import Buff from '@/Buff';
import BuffUtil from '@/BuffUtil';
import SelectUtil from '@/SelectUtil';
import BuffCommon from 'code/Core/Common/BuffCommon';
import MovementCommon from 'code/Core/Common/MovementCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
export default class DK_PlagueDomain extends AbilityBase {
    static instance: DK_PlagueDomain;
    buffType: AppBuffType = {
        id: 'buff_DK_PlagueDomain',
        name: this.abilityName,
        ubertip: this.ubertip,
        art: this.art,
        interval: 1,
        dur: 6,
        onInterval: this.buffInterval.bind(this),
        onDestroy: this.buffEnd.bind(this),
        targetAttach: 'origin',
        targetArt: 'Abilities\\Spells\\Human\\Brilliance\\Brilliance.mdl',
    };
    deBuffType: AppBuffType = {
        id: 'buff_DK_PlagueDomain_debuff',
        name: this.abilityName,
        ubertip: '在瘟疫领域中攻击和移速都受到降低',
        art: this.art,
        dur: 2,
        attribute: {
            attackSpd_p: -0.3,
            move_speed_p: -0.25,
        },
    };
    onMissileReach(p: TargetMissileConfig) {
        let lv = this.getAbilityLevel(p.caster);
        let dmg = 10 * lv + UnitCommon.取法强(p.caster) * (0.6 + 0.1 * lv);
        DamageSystemInstance.applyHeal(p.caster, p.caster, dmg, this.id);
    }
    buffEnd(buff: Buff) {
        SetUnitVertexColor(buff.getParent(), 255, 255, 255, 255);
    }
    buffInterval(buff: Buff) {
        let source = buff.getCaster();
        let lv = this.getAbilityLevel(source);
        let dmg = 25 * lv + UnitCommon.取法强(source) * (0.7 + 0.3 * lv);
        let es = SelectUtil.getEnemyUnitsInRange(source, 450);
        for (let e of es) {
            // BuffUtil.addBuff(e, this.deBuffType.id, source);
            BuffCommon.addBuff({ target: e, caster: source, buffTypeId: this.deBuffType.id, ablityId: this.id });
            DamageSystemInstance.applyPoisionDamage(e, source, dmg, this.id);
            DestroyEffect(AddSpecialEffectTarget('Abilities\\Spells\\Undead\\DeathCoil\\DeathCoilSpecialArt.mdl', e, 'origin'));

            MovementCommon.TargetMissile({
                curX: GetUnitX(e),
                curY: GetUnitY(e),
                target: source,
                caster: source,
                missile: 'Abilities\\Weapons\\IllidanMissile\\IllidanMissile.mdl',
                speed: 400,
                onReach: this.onMissileReach.bind(this),
            });
        }
    }
    constructor(id: string) {
        super(id);
        DK_PlagueDomain.instance = this;
        this.init();
        se.onUnitSpellEffect(this.spellEffect.bind(this), this.id);
    }
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        // BuffUtil.addBuff(source, this.buffType.id, source);
        BuffCommon.addBuff({ target: source, caster: source, buffTypeId: this.buffType.id, ablityId: this.id });
        SetUnitVertexColor(source, 100, 255, 100, 60);
    }
    spellEffect() {
        this.cast(GetUnitX(GetTriggerUnit()), GetUnitY(GetTriggerUnit()), GetTriggerUnit(), GetSpellTargetUnit());
    }
    init() {
        BuffUtil.registerBuffType(this.buffType);
        BuffUtil.registerBuffType(this.deBuffType);
    }
}
